﻿using System;
using System.Collections.Generic;
using System.Text;
using MarketSimulator.Utils.Market;
using MarketSimulator.Utils.Maps;
using jade.core;

namespace MarketSimulator.Utils.Attributes
{
    public class BuyerAttributes : GeneralAttributes
    {
        #region Properties

        public const string BuyerServiceName = "[BUYER]";
        /// <summary>
        /// Product Name | Quantity | Price per Unit
        /// </summary>
        private const string ProductInfoFormat = "[{0} | want {1} items]";

        /// <summary>
        /// Product List
        /// </summary>
        public IList<Product> ShoppingList { get; set; }

        /// <summary>
        /// Seller Location
        /// </summary>
        public City Location { get; set; }

        #endregion

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="location"></param>
        /// <param name="shoppingList"></param>
        public BuyerAttributes(Agent agent, City location, IList<Product> shoppingList, Action<string> agentsChat) : base(agentsChat)
        {
            JadeAgent = agent;
            Location = location;
            ShoppingList = shoppingList;
            
        }

        #region Methods
        
        /// <summary>
        /// Register Actor
        /// </summary>
        public override void RegisterAgent()
        {
            YellowPages.RegisterService(BuyerServiceName, JadeAgent);
        }

        /// <summary>
        /// Get Product Information as String
        /// </summary>
        /// <returns></returns>
        public string GetShoppingListString()
        {
            StringBuilder stringBuilder = new StringBuilder();
            foreach (var product in ShoppingList)
            {
                stringBuilder.AppendFormat(ProductInfoFormat, product.Name, product.Quantity);
            }

            return stringBuilder.ToString();
        }

        #endregion
    }
}
